package io.api.modules.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.admin.common.service.impl.CrudServiceImpl;
import cn.hutool.core.util.StrUtil;
import io.admin.common.utils.ConvertUtils;
import io.api.modules.project.dao.UserProjectDao;
import io.api.modules.project.dto.UserProjectDTO;
import io.api.modules.project.entity.UserProjectEntity;
import io.api.modules.project.service.UserProjectService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 项目人员关系表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2024-07-12
 */
@Service
public class UserProjectServiceImpl extends CrudServiceImpl<UserProjectDao, UserProjectEntity, UserProjectDTO> implements UserProjectService {

    @Override
    public QueryWrapper<UserProjectEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<UserProjectEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public UserProjectDTO selectByProjectIdAndUserId(Long projectId, Long userId) {
        UserProjectEntity entity = baseDao.selectOne(new LambdaQueryWrapper<UserProjectEntity>()
                .eq(UserProjectEntity::getProjectId, projectId)
                .eq(UserProjectEntity::getUserId, userId)
        );
        return ConvertUtils.sourceToTarget(entity, UserProjectDTO.class);
    }

}